home *** CD-ROM | disk | FTP | other *** search
/ Aminet 39 / Aminet 39 (2000)(Schatztruhe)[!][Oct 2000].iso / Aminet / dev / basic / pmDevBas.lha / PullDownMenu.bas < prev    next >
Encoding:
BASIC Source File  |  2000-07-01  |  17.1 KB  |  739 lines

  1. ' *********************************************************************
  2. '   PullDownMenu © 1996-97 by Henrik Isaksson -- All Rights Reserved
  3. '                           V. 1.0 (05.09.98)
  4. '
  5. '                 C to HBASIC conversion 1.0 (30.6.00)
  6. '               by Dámaso D. Estévez <amidde@arrakis.es>
  7. '              AmiSpaTra - http://www.arrakis.es/~amidde/
  8. '
  9. '   This example create a Workbench menu simulation and uses a hook
  10. ' Este ejemplo crea una simulación del menú del WB y utiliza un resorte
  11. ' *********************************************************************
  12.  
  13. REM $include pm.bh
  14. REM $include exec.bh
  15. REM $include intuition.bh
  16. REM $include utility.bc
  17.  
  18. pmb&  = NULL&    ' PopUpMenuBase
  19. ib&   = NULL&    ' IntuitionBase
  20. ub&   = NULL&    ' UtilityBase
  21. gb&   = NULL&    ' GfxBase
  22. w&    = NULL&    ' Window
  23.  
  24. im&   = NULL&    ' IntuiMessage
  25. p&    = NULL&    ' PopupMenu
  26. r&    = TRUE&    ' Status flag (loop) / Bandera de estado (bucle)
  27. ok&   = FALSE&   ' Status flag / Bandera de estado
  28.  
  29. DIM mtags&(40)   ' Window Taglist / Lista de atributos para la ventana
  30.  
  31. '     Hook struct simulation
  32. ' Simulación de la estructura Hook 
  33. ' --------------------------------
  34. DIM MenuHandler%(Hook_sizeof%\2)
  35.  
  36. '      Settings for to use hooks
  37. ' Preferencias para el uso de resortes
  38. ' ------------------------------------
  39. REM $NOAUTODIM
  40. REM $NOARRAY
  41. REM $NOBREAK
  42. REM $NOOVERFLOW
  43. REM $NOEVENT
  44. REM $NOSTACK
  45.  
  46. ' =====================================================================
  47.  
  48. FUNCTION MenuHandlerFunc&(BYVAL hook&,BYVAL object&,BYVAL msg&)
  49. SHARED r&
  50. STATIC i&
  51.  
  52.     MenuHandlerFunc& = FALSE&
  53.  
  54.     PRINT "---"
  55.     PRINT "Title:   "+CHR$(34)+PEEK$(PEEKL(object&+pm_Title%))+CHR$(34)
  56.     PRINT "UserData:";PEEKL(object&+pm_UserData%)
  57.     PRINT "ID:      ";PEEKL(object&+pm_ID%)
  58.  
  59.     '   Mr Issakson says what this is the way
  60.     '  of finding is the item is checked or not:
  61.     ' &h40000000 = CHECKIT, &h80000000 = CHECKED
  62.     '
  63.     ' El Sr. Issakson señala que esta es la forma
  64.     '    de comprobar si un ítem está activado
  65.     '        (marca de verificación) o no.
  66.     ' &h40000000 = CHECKIT, &h80000000 = CHECKED
  67.     ' --------------------------------------------
  68.     IF(PEEKL(object&+pm_Flags%) AND &h40000000) THEN
  69.         print "Checked?  ";
  70.         IF (PEEKL(object&+pm_Flags%) AND &h80000000) THEN
  71.              PRINT "Yes"
  72.         ELSE
  73.              PRINT "No"
  74.         END IF
  75.         PRINT
  76.     END IF
  77.  
  78.     IF(PEEKL(object&+pm_UserData%)=5&) THEN
  79.         '       Mr Issakson uses other solution more elegant
  80.         ' in your C code, I know... I tried convert it to HBasic,
  81.         '      but my code always finnished with a guru 8'(...
  82.         ' and I decided use the HBasic shared var for simulate it.
  83.         '
  84.         '   El Sr. Issakson utiliza otra solución más elegante
  85.         '  en su código en C, lo sé... he intentado reproducirla
  86.         '     pero mi código siempre acababa en un gurú 8'(..
  87.         '   así que decidí utilizar las variables compartidas
  88.         '          del HBasic para simular su función.
  89.         r&=FALSE&
  90.     END IF
  91.  
  92.     MenuHandlerFunc& = TRUE&
  93.  
  94. END FUNCTION
  95.  
  96. '               --------------------------------------------
  97.  
  98. FUNCTION MakeTestMenu&()
  99. LOCAL i&,pi&,mpi&,tags&
  100.  
  101. ' Taglist / Lista de atributos
  102. ' ----------------------------
  103. DIM tags&(24)
  104.  
  105. ' Items or menu pointer arrays / Matrices de punteros a ítems o menús
  106. ' -------------------------------------------------------------------
  107. DIM mpi&(10)    ' Main
  108. DIM  pi&(15)    ' Aux.
  109.  
  110.     ' Workbench item menu / Ítem del menú Workbench
  111.     ' =============================================
  112.  
  113.     ' PMCheckItem
  114.  
  115.     TAGLIST VARPTR(tags&(0)), _
  116.         PM_Title&,   SADD("Backdrop?"+CHR$(0)), _
  117.         PM_ID&,      1&, _
  118.         PM_Checkit&, TRUE&, _
  119.         PM_CommKey&, SADD("B"+CHR$(0)), _
  120.         TAG_DONE&
  121.  
  122.     pi&(1) = PM_MakeItemA&(VARPTR(tags&(0)))
  123.  
  124.     ' PMItem
  125.  
  126.     TAGLIST VARPTR(tags&(0)), _
  127.         PM_Title&,   SADD("Execute command..."+CHR$(0)), _
  128.         PM_CommKey&, SADD("E"+CHR$(0)), _
  129.         TAG_DONE&
  130.  
  131.     pi&(2) = PM_MakeItemA&(VARPTR(tags&(0)))
  132.  
  133.     TAGLIST VARPTR(tags&(0)), _
  134.         PM_Title&,   SADD("Redraw All"+CHR$(0)), _
  135.         TAG_DONE&
  136.  
  137.     pi&(3) = PM_MakeItemA&(VARPTR(tags&(0)))
  138.  
  139.     TAGLIST VARPTR(tags&(0)), _
  140.         PM_Title&,   SADD("Update All"+CHR$(0)), _
  141.         TAG_DONE&
  142.  
  143.     pi&(4) = PM_MakeItemA&(VARPTR(tags&(0)))
  144.  
  145.     TAGLIST VARPTR(tags&(0)), _
  146.         PM_Title&,   SADD("Last Message"+CHR$(0)), _
  147.         TAG_DONE&
  148.  
  149.     pi&(5) = PM_MakeItemA&(VARPTR(tags&(0)))
  150.  
  151.     TAGLIST VARPTR(tags&(0)), _
  152.         PM_Title&,   SADD("About..."+CHR$(0)), _
  153.         PM_CommKey&, SADD("?"+CHR$(0)), _
  154.         TAG_DONE&
  155.  
  156.     pi&(6) = PM_MakeItemA&(VARPTR(tags&(0)))
  157.  
  158.     TAGLIST VARPTR(tags&(0)), _
  159.         PM_Title&,   SADD("Quit"+CHR$(0)), _
  160.         PM_UserData&, 5&, _
  161.         PM_CommKey&,  SADD("Q"+CHR$(0)), _
  162.         TAG_DONE&
  163.  
  164.     pi&(7) = PM_MakeItemA&(VARPTR(tags&(0)))
  165.  
  166.     ' Grouping items / Agrupando ítems en un submenú
  167.     ' ----------------------------------------------
  168.  
  169.     TAGLIST VARPTR(tags&(0)), _
  170.         PM_Dummy&, 0&, _
  171.         TAG_DONE&
  172.  
  173.     FOR i& = 1 TO 7
  174.         TAGLIST VARPTR(tags&((i&-1)*2)), _
  175.             PM_Item&, pi&(i&), _
  176.             TAG_DONE&
  177.     NEXT i&
  178.  
  179.     mpi&(0) = PM_MakeMenuA&(VARPTR(tags&(0)))
  180.  
  181.     ' Creating the Workbench item and link with their submenu
  182.     '      Creando ítem Workbench y enlace con su submenú
  183.     ' -------------------------------------------------------
  184.  
  185.     TAGLIST VARPTR(tags&(0)), _
  186.         PM_Title&,    SADD("Workbench"+CHR$(0)), _
  187.         PM_Sub&,      mpi&(0), _
  188.         PM_UserData&, 5986&, _
  189.         PM_NoSelect&, FALSE&, _
  190.         TAG_DONE&
  191.  
  192.     mpi&(1) = PM_MakeItemA&(VARPTR(tags&(0)))
  193.  
  194.     ' =============================================================
  195.  
  196.     ' Window item menu / Ítem del menú Window
  197.     ' =======================================
  198.  
  199.     ' PMItem
  200.  
  201.     TAGLIST VARPTR(tags&(0)), _
  202.         PM_Title&,    SADD("New Drawer"+CHR$(0)), _
  203.         PM_CommKey&,  SADD("N"+CHR$(0)), _
  204.         PM_Disabled&, TRUE&, _
  205.         TAG_DONE&
  206.  
  207.     pi&(1) = PM_MakeItemA&(VARPTR(tags&(0)))
  208.  
  209.     TAGLIST VARPTR(tags&(0)), _
  210.         PM_Title&,    SADD("Open Parent"+CHR$(0)), _
  211.         PM_Disabled&, TRUE&, _
  212.         TAG_DONE&
  213.  
  214.     pi&(2) = PM_MakeItemA&(VARPTR(tags&(0)))
  215.  
  216.     TAGLIST VARPTR(tags&(0)), _
  217.         PM_Title&,   SADD("Close"+CHR$(0)), _
  218.         PM_CommKey&, SADD("K"+CHR$(0)), _
  219.         PM_Disabled&, TRUE&, _
  220.         TAG_DONE&
  221.  
  222.     pi&(3) = PM_MakeItemA&(VARPTR(tags&(0)))
  223.  
  224.     TAGLIST VARPTR(tags&(0)), _
  225.         PM_Title&,   SADD("Update"+CHR$(0)), _
  226.         PM_Disabled&, TRUE&,_
  227.         TAG_DONE&
  228.  
  229.     pi&(4) = PM_MakeItemA&(VARPTR(tags&(0)))
  230.  
  231.     TAGLIST VARPTR(tags&(0)), _
  232.         PM_Title&,   SADD("Select Contents"+CHR$(0)), _
  233.         PM_CommKey&, SADD("A"+CHR$(0)), _
  234.         TAG_DONE&
  235.  
  236.     pi&(5) = PM_MakeItemA&(VARPTR(tags&(0)))
  237.  
  238.     TAGLIST VARPTR(tags&(0)), _
  239.         PM_Title&,   SADD("Clean Up"+CHR$(0)), _
  240.         PM_CommKey&,  SADD("."+CHR$(0)), _
  241.         TAG_DONE&
  242.  
  243.     pi&(6) = PM_MakeItemA&(VARPTR(tags&(0)))
  244.  
  245.     ' Snapshot submenu / Submenú Snapshot
  246.  
  247.         ' Subitems
  248.  
  249.         TAGLIST VARPTR(tags&(0)), _
  250.             PM_Title&, SADD("Window"+CHR$(0)), _
  251.             TAG_DONE&
  252.  
  253.         pi&(7) = PM_MakeItemA&(VARPTR(tags&(0)))
  254.  
  255.         TAGLIST VARPTR(tags&(0)), _
  256.             PM_Title&, SADD("All"+CHR$(0)), _
  257.             TAG_DONE&
  258.  
  259.         pi&(8) = PM_MakeItemA&(VARPTR(tags&(0)))
  260.  
  261.         TAGLIST VARPTR(tags&(0)), _
  262.             PM_Dummy&, 0&, _
  263.             PM_Item&,  pi&(7), _
  264.             PM_Item&,  pi&(8), _
  265.             TAG_DONE&
  266.  
  267.         pi&(0) = PM_MakeMenuA&(VARPTR(tags&(0)))
  268.  
  269.     TAGLIST VARPTR(tags&(0)), _
  270.         PM_Title&, SADD("Snapshot"+CHR$(0)), _
  271.         PM_Sub&,   pi&(0), _
  272.         TAG_DONE&
  273.  
  274.     pi&(7) = PM_MakeItemA&(VARPTR(tags&(0)))
  275.  
  276.     ' Show submenu / Submenú Show
  277.  
  278.         ' Subitems
  279.  
  280.         ' Excluding items
  281.         TAGLIST VARPTR(tags&(0)), _
  282.             3&, 0&
  283.  
  284.         pi&(0)=PM_ExLstA&(VARPTR(tags&(0)))
  285.  
  286.         TAGLIST VARPTR(tags&(0)), _
  287.             PM_Title&,   SADD("Only Icons"+CHR$(0)), _
  288.             PM_ID&,      2&, _
  289.             PM_Checkit&, TRUE&, _
  290.             PM_Exclude&, pi&(0), _
  291.             PM_Checked&, TRUE&, _
  292.             TAG_DONE&
  293.  
  294.         pi&(8) = PM_MakeItemA&(VARPTR(tags&(0)))
  295.  
  296.         ' Excluding items
  297.  
  298.         TAGLIST VARPTR(tags&(0)), _
  299.             2&, 0&
  300.  
  301.         pi&(0)=PM_ExLstA&(VARPTR(tags&(0)))
  302.  
  303.         TAGLIST VARPTR(tags&(0)), _
  304.             PM_Title&,   SADD("All"+CHR$(0)), _
  305.             PM_ID&,      3&, _
  306.             PM_Checkit&, TRUE&, _
  307.             PM_Exclude&, pi&(0), _
  308.             TAG_DONE&
  309.  
  310.         pi&(9) = PM_MakeItemA&(VARPTR(tags&(0)))
  311.  
  312.         TAGLIST VARPTR(tags&(0)), _
  313.             PM_Dummy&,    0&, _
  314.             PM_Item&,     pi&(8), _
  315.             PM_Item&,     pi&(9), _
  316.             TAG_DONE&
  317.  
  318.         pi&(0) = PM_MakeMenuA&(VARPTR(tags&(0)))
  319.  
  320.     TAGLIST VARPTR(tags&(0)), _
  321.         PM_Title&,    SADD("Show"+CHR$(0)), _
  322.         PM_Sub&,      pi&(0),_
  323.         PM_Disabled&, TRUE&, _
  324.         TAG_DONE&
  325.  
  326.     pi&(8) = PM_MakeItemA&(VARPTR(tags&(0)))
  327.  
  328.     ' View By submenu / Submenu View By
  329.  
  330.         ' Subitems
  331.  
  332.         ' Excluding items
  333.  
  334.         TAGLIST VARPTR(tags&(0)), _
  335.             5&, 6&, 7&, 0&
  336.  
  337.         pi&(0)=PM_ExLstA&(VARPTR(tags&(0)))
  338.  
  339.         TAGLIST VARPTR(tags&(0)), _
  340.             PM_Title&,   SADD("Icon"+CHR$(0)), _
  341.             PM_ID&,      4&, _
  342.             PM_Checkit&, TRUE&, _
  343.             PM_Exclude&, pi&(0), _
  344.             PM_Checked&, TRUE&, _
  345.             TAG_DONE&
  346.  
  347.         pi&(9) = PM_MakeItemA&(VARPTR(tags&(0)))
  348.  
  349.         ' Excluding items
  350.  
  351.         TAGLIST VARPTR(tags&(0)), _
  352.             4&, 6&, 7&, 0&
  353.  
  354.         pi&(0)=PM_ExLstA&(VARPTR(tags&(0)))
  355.  
  356.         TAGLIST VARPTR(tags&(0)), _
  357.             PM_Title&,   SADD("Name"+CHR$(0)), _
  358.             PM_ID&,      5&, _
  359.             PM_Checkit&, TRUE&, _
  360.             PM_Exclude&, pi&(0), _
  361.             TAG_DONE&
  362.  
  363.         pi&(10) = PM_MakeItemA&(VARPTR(tags&(0)))
  364.  
  365.         ' Excluding items
  366.  
  367.         TAGLIST VARPTR(tags&(0)), _
  368.             4&, 5&, 7&, 0&
  369.  
  370.         pi&(0)=PM_ExLstA&(VARPTR(tags&(0)))
  371.  
  372.         TAGLIST VARPTR(tags&(0)), _
  373.             PM_Title&,   SADD("Date"+CHR$(0)), _
  374.             PM_ID&,      6&, _
  375.             PM_Checkit&, TRUE&, _
  376.             PM_Exclude&, pi&(0), _
  377.             TAG_DONE&
  378.  
  379.         pi&(11) = PM_MakeItemA&(VARPTR(tags&(0)))
  380.  
  381.         ' Excluding items
  382.  
  383.         TAGLIST VARPTR(tags&(0)), _
  384.             4&, 5&, 6&, 0&
  385.  
  386.         pi&(0)=PM_ExLstA&(VARPTR(tags&(0)))
  387.  
  388.         TAGLIST VARPTR(tags&(0)), _
  389.             PM_Title&,   SADD("Size"+CHR$(0)), _
  390.             PM_ID&,      7&, _
  391.             PM_Checkit&, TRUE&, _
  392.             PM_Exclude&, pi&(0), _
  393.             TAG_DONE&
  394.  
  395.         pi&(12) = PM_MakeItemA&(VARPTR(tags&(0)))
  396.  
  397.         TAGLIST VARPTR(tags&(0)), _
  398.             PM_Dummy&, 0&, _
  399.             PM_Item&,  pi&(9), _
  400.             PM_Item&,  pi&(10), _
  401.             PM_Item&,  pi&(11), _
  402.             PM_Item&,  pi&(12), _
  403.             PM_Disabled&, TRUE&, _
  404.             TAG_DONE&
  405.  
  406.         pi&(0) = PM_MakeMenuA&(VARPTR(tags&(0)))
  407.  
  408.     TAGLIST VARPTR(tags&(0)), _
  409.         PM_Title&,  SADD("View By"+CHR$(0)), _
  410.         PM_Sub&,    pi&(0), _
  411.         TAG_DONE&
  412.  
  413.     pi&(9) = PM_MakeItemA&(VARPTR(tags&(0)))
  414.  
  415.     ' Grouping items / Agrupando ítems en un submenú
  416.     ' ----------------------------------------------
  417.  
  418.     TAGLIST VARPTR(tags&(0)), _
  419.         PM_Dummy&, 0&, _
  420.         TAG_DONE&
  421.  
  422.     FOR i& = 1 TO 9
  423.         TAGLIST VARPTR(tags&((i&-1)*2)), _
  424.             PM_Item&, pi&(i&), _
  425.             TAG_DONE&
  426.     NEXT i&
  427.  
  428.     mpi&(0) = PM_MakeMenuA&(VARPTR(tags&(0)))
  429.  
  430.     TAGLIST VARPTR(tags&(0)), _
  431.         PM_Title&, SADD("Window"+CHR$(0)), _
  432.         PM_Sub&,   mpi&(0), _
  433.         TAG_DONE&
  434.  
  435.     mpi&(2) = PM_MakeItemA&(VARPTR(tags&(0)))
  436.  
  437.     ' =============================================================
  438.  
  439.     ' Icons item menu / Ítem del menú Icons
  440.     ' =====================================
  441.  
  442.     ' PMItem
  443.  
  444.     TAGLIST VARPTR(tags&(0)), _
  445.         PM_Title&,   SADD("Open"+CHR$(0)), _
  446.         PM_CommKey&, SADD("O"+CHR$(0)), _
  447.         TAG_DONE&
  448.  
  449.     pi&(1) = PM_MakeItemA&(VARPTR(tags&(0)))
  450.  
  451.     TAGLIST VARPTR(tags&(0)), _
  452.         PM_Title&,   SADD("Copy"+CHR$(0)), _
  453.         PM_CommKey&, SADD("C"+CHR$(0)), _
  454.         TAG_DONE&
  455.  
  456.     pi&(2) = PM_MakeItemA&(VARPTR(tags&(0)))
  457.  
  458.     TAGLIST VARPTR(tags&(0)), _
  459.         PM_Title&,   SADD("Rename..."+CHR$(0)), _
  460.         PM_CommKey&, SADD("R"+CHR$(0)), _
  461.         TAG_DONE&
  462.  
  463.     pi&(3) = PM_MakeItemA&(VARPTR(tags&(0)))
  464.  
  465.     TAGLIST VARPTR(tags&(0)), _
  466.         PM_Title&,   SADD("Information..."+CHR$(0)), _
  467.         PM_CommKey&, SADD("I"+CHR$(0)),_
  468.         TAG_DONE&
  469.  
  470.     pi&(4) = PM_MakeItemA&(VARPTR(tags&(0)))
  471.  
  472.     TAGLIST VARPTR(tags&(0)), _
  473.         PM_Title&,   SADD("Snapshot..."+CHR$(0)), _
  474.         PM_CommKey&, SADD("S"+CHR$(0)), _
  475.         TAG_DONE&
  476.  
  477.     pi&(5) = PM_MakeItemA&(VARPTR(tags&(0)))
  478.  
  479.     TAGLIST VARPTR(tags&(0)), _
  480.         PM_Title&,   SADD("UnSnapshot"+CHR$(0)), _
  481.         PM_CommKey&,  SADD("U"+CHR$(0)), _
  482.         TAG_DONE&
  483.  
  484.     pi&(6) = PM_MakeItemA&(VARPTR(tags&(0)))
  485.  
  486.     TAGLIST VARPTR(tags&(0)), _
  487.         PM_Title&,   SADD("Leave Out"+CHR$(0)), _
  488.         PM_CommKey&, SADD("L"+CHR$(0)), _
  489.         TAG_DONE&
  490.  
  491.     pi&(7) = PM_MakeItemA&(VARPTR(tags&(0)))
  492.  
  493.     TAGLIST VARPTR(tags&(0)), _
  494.         PM_Title&,   SADD("Put Away"+CHR$(0)), _
  495.         PM_CommKey&,  SADD("P"+CHR$(0)), _
  496.         TAG_DONE&
  497.  
  498.     pi&(8) = PM_MakeItemA&(VARPTR(tags&(0)))
  499.  
  500.     TAGLIST VARPTR(tags&(0)), _
  501.         PM_TitleBar&, TRUE&, _
  502.         TAG_DONE&
  503.  
  504.     pi&(9) = PM_MakeItemA&(VARPTR(tags&(0)))
  505.  
  506.     TAGLIST VARPTR(tags&(0)), _
  507.         PM_Title&,    SADD("Delete..."+CHR$(0)), _
  508.         PM_Disabled&, TRUE&, _
  509.         TAG_DONE&
  510.  
  511.     pi&(10) = PM_MakeItemA&(VARPTR(tags&(0)))
  512.  
  513.     TAGLIST VARPTR(tags&(0)), _
  514.         PM_Title&,   SADD("Format Disk..."+CHR$(0)), _
  515.         TAG_DONE&
  516.  
  517.     pi&(11) = PM_MakeItemA&(VARPTR(tags&(0)))
  518.  
  519.     TAGLIST VARPTR(tags&(0)), _
  520.         PM_Title&,   SADD("Empty Trash"+CHR$(0)), _
  521.         PM_CommKey&, TRUE&, _
  522.         TAG_DONE&
  523.  
  524.     pi&(12) = PM_MakeItemA&(VARPTR(tags&(0)))
  525.  
  526.     ' Grouping items / Agrupando ítems en un submenú
  527.     ' ----------------------------------------------
  528.  
  529.     TAGLIST VARPTR(tags&(0)), _
  530.         PM_Dummy&, 0&, _
  531.         TAG_DONE&
  532.  
  533.     FOR i& = 1 TO 12
  534.         TAGLIST VARPTR(tags&((i&-1)*2)), _
  535.             PM_Item&, pi&(i&), _
  536.             TAG_DONE&
  537.     NEXT i&
  538.  
  539.     mpi&(0) = PM_MakeMenuA&(VARPTR(tags&(0)))
  540.  
  541.     TAGLIST VARPTR(tags&(0)), _
  542.         PM_Title&, SADD("Icons"+CHR$(0)), _
  543.         PM_Sub&,   mpi&(0), _
  544.         TAG_DONE&
  545.  
  546.     mpi&(3) = PM_MakeItemA&(VARPTR(tags&(0)))
  547.  
  548.     ' =============================================================
  549.  
  550.     ' Tools item menu / Ítem del menú Tools
  551.     ' =====================================
  552.  
  553.     ' PMItem
  554.     ' ------
  555.  
  556.     TAGLIST VARPTR(tags&(0)), _
  557.         PM_Title&, SADD("ResetWB"+CHR$(0)), _
  558.         TAG_DONE&
  559.  
  560.     pi&(1) = PM_MakeItemA&(VARPTR(tags&(0)))
  561.  
  562.     ' Grouping items / Agrupando ítems en un submenú
  563.     ' ----------------------------------------------
  564.  
  565.     TAGLIST VARPTR(tags&(0)), _
  566.         PM_Dummy&, 0&, _
  567.         PM_Item&,  pi&(1),_
  568.         TAG_DONE&
  569.  
  570.     mpi&(0) = PM_MakeMenuA&(VARPTR(tags&(0)))
  571.  
  572.     TAGLIST VARPTR(tags&(0)), _
  573.         PM_Title&, SADD("Tools"+CHR$(0)), _
  574.         PM_Sub&,   mpi&(0), _
  575.         TAG_DONE&
  576.  
  577.     mpi&(4) = PM_MakeItemA&(VARPTR(tags&(0)))
  578.  
  579.     ' =========================
  580.     '  Creating the popup menu
  581.     ' Creando el menú emergente
  582.     ' =========================
  583.  
  584.     FOR i& = 1 TO 4
  585.         TAGLIST VARPTR(tags&((i&-1)*2)), _
  586.             PM_Item&, mpi&(i&), _
  587.             TAG_DONE&
  588.     NEXT i&
  589.  
  590.     MakeTestMenu& = PM_MakeMenuA&(VARPTR(tags&(0)))
  591.  
  592. END FUNCTION
  593.  
  594. ' =====================================================================
  595. '                          The code / El código
  596. ' =====================================================================
  597.  
  598. '            "Opening" all libraries needed
  599. ' Abriendo y preparando todas las bibliotecas necesarias
  600. ' ------------------------------------------------------
  601.  
  602. LIBRARY OPEN "exec.library"
  603. LIBRARY OPEN "popupmenu.library",POPUPMENU_VERSION&
  604.  
  605. pmb&=LIBRARY("popupmenu.library")
  606.  
  607. IF pmb& <> NULL& THEN
  608.     LIBRARY VARPTR "popupmenu.library", pmb&
  609.     ib& = PEEKL(pmb& + pmb_IntuitionBase%)
  610.     IF ib& <> NULL& THEN
  611.         LIBRARY VARPTR "intuition.library", ib&
  612.         gb& = PEEKL(pmb& + pmb_GfxBase%)
  613.         IF gb& <> NULL& THEN
  614.             LIBRARY VARPTR "graphics.library", gb&
  615.             ok& = TRUE&
  616.         END IF
  617.     END IF
  618. END IF
  619.  
  620. '  First, a C struct simulation (see the imsg var in original C code)
  621. '      Primero, reservo espacio para simular una estructura en C
  622. ' (consulte la función de la variable imsg en el código original en C)
  623. ' --------------------------------------------------------------------
  624. imsg&=AllocMem&(IntuiMessage_sizeof%,MEMF_ANY& OR MEMF_CLEAR&)
  625. IF imsg& = NULL& THEN
  626.     ok&= FALSE&
  627. END IF
  628.  
  629. IF ok& = TRUE& THEN
  630.  
  631.     ' Preparing my menu / Preparando mi menú
  632.     ' --------------------------------------
  633.     p& = MakeTestMenu&()
  634.  
  635.     IF p& <> NULL& THEN
  636.  
  637.         '   Window properties
  638.         ' Atributos de la ventana
  639.         ' -----------------------
  640.         TAGLIST VARPTR(mtags&(0)),_
  641.             WA_IDCMP&,       IDCMP_CLOSEWINDOW& OR IDCMP_MOUSEBUTTONS& OR IDCMP_VANILLAKEY&, _
  642.             WA_RMBTrap&,     TRUE&, _
  643.             WA_DragBar&,     TRUE&, _
  644.             WA_Width&,       150, _
  645.             WA_Height&,      100, _
  646.             WA_Left&,        0, _
  647.             WA_Top&,         100, _
  648.             WA_Title&,       SADD("PullDown Menus"+CHR$(0)), _
  649.             WA_CloseGadget&, TRUE&,_
  650.             TAG_DONE&
  651.  
  652.         '    Opening the window: this window is only needed to find out
  653.         '  when AND where the MENU should appear AND wich SCREEN it's on.
  654.         ' Abriendo la ventana: sólo es necesaria para saber dónde y cuándo
  655.         '       el menú emergente debe aparecer y sobre qué pantalla.
  656.         ' ----------------------------------------------------------------
  657.         w& = OpenWindowTagList&(NULL&, VARPTR(mtags&(0)))
  658.  
  659.         IF w& <> NULL& THEN
  660.  
  661.             ' Creating a Hook struct / Creando una estructura Hook
  662.             ' ----------------------------------------------------
  663.             INITHOOK VARPTR(MenuHandler%(0)),VARPTRS(MenuHandlerFunc&)
  664.  
  665.             WHILE r&
  666.  
  667.                 '  Waiting a message
  668.                 ' Esperando un mensaje
  669.                 ' --------------------
  670.                 dummy& = WaitPort&(PEEKL(w&+UserPort%))
  671.  
  672.                 DO
  673.  
  674.                     '    Get the message
  675.                     ' Se obtiene el mensaje
  676.                     ' ---------------------
  677.                     im& = GetMsg&(PEEKL(w&+UserPort%))
  678.                     IF im& THEN
  679.  
  680.                         '   ... but we will work with a copy
  681.                         ' ... pero se trabajará con una copia
  682.                         ' -----------------------------------
  683.                         CopyMem im&, imsg&, IntuiMessage_sizeof%
  684.                         ReplyMsg im&
  685.  
  686.                         TAGLIST VARPTR(mtags&(0)),_
  687.                             PM_AutoPullDown&, TRUE&,_
  688.                             PM_MenuHandler&,  VARPTR(MenuHandler%(0)), _
  689.                             TAG_DONE&
  690.  
  691.                         dummy& = PM_FilterIMsgA&(w&,p&,imsg&,VARPTR(mtags&(0)))
  692.  
  693.                         IF PEEKL(imsg&+Class%) =IDCMP_CLOSEWINDOW& THEN r&=FALSE&
  694.                         
  695.                     ELSE
  696.  
  697.                         EXIT LOOP
  698.  
  699.                     END IF
  700.  
  701.                 LOOP
  702.  
  703.             WEND
  704.  
  705.             CloseWindow& w&
  706.  
  707.         ELSE
  708.  
  709.             PRINT "Window error!"
  710.  
  711.         END IF
  712.  
  713.         PM_FreePopupMenu& p&
  714.  
  715.     ELSE
  716.  
  717.         PRINT "Menu error!"
  718.  
  719.     END IF
  720.  
  721. ELSE
  722.  
  723.     PRINT "The hook struct allocation or the libraries have failed!"
  724.  
  725. END IF
  726.  
  727. IF imsg& <> NULL& THEN FreeMem imsg&,IntuiMessage_sizeof%
  728.  
  729. IF gb& <> NULL& THEN LIBRARY VARPTR "graphics.library",  NULL&
  730. IF ib& <> NULL& THEN LIBRARY VARPTR "intuition.library", NULL&
  731.  
  732. '          Safe, even if the program fails to open the libraries
  733. ' Método seguro, incluso aunque el programa falle al abrir las bibliotecas
  734. ' ------------------------------------------------------------------------
  735. LIBRARY CLOSE "popupmenu.library"
  736. LIBRARY CLOSE "exec.library"
  737.  
  738. END
  739.